package happywing.client.widget.icon;

import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;

import happywing.client.widget.UIItem;
import happywing.shared.StringUtils;

public class Icon extends UIItem {
	private static final String ROOTPATH="/images/icons/";
	
	private Image image;
	private FlowPanel imagePanel;
	private FlowPanel namePanel;
	private FlowPanel summaryPanel;
	private FlowPanel iconPanel;
	
	
	public Icon(String pngName,String name,String summary,IconState iconState){
		image=new Image();
		image.setUrl(ROOTPATH+pngName);
		
		imagePanel=new FlowPanel();
		imagePanel.add(image);
		imagePanel.setStyleName("uiitem-icon-image");
		
		if(null!=iconState){
			imagePanel.add(iconState);
		}
		
		namePanel=new FlowPanel();
		namePanel.add(new HTML(name));
		namePanel.setStyleName("uiitem-icon-name");
		
		summaryPanel=new FlowPanel();
		summaryPanel.add(new HTML(StringUtils.cutWithDot(summary, 40)));
		summaryPanel.setStyleName("uiitem-icon-summary");
		
		iconPanel=new FlowPanel();
		iconPanel.add(imagePanel);
		iconPanel.add(namePanel);
		iconPanel.add(summaryPanel);
		
		initWidget(iconPanel);
		setStyleName("uiitem-icon");
	}
	
	public Icon(String pngName,String name,String summary){
		this(pngName,name,summary,null);
	}
	

	
	
}
